const fs = require('fs');
const getCss = require('./getCss');

module.exports = function(opt, glyphList) {
  let cssContent = getCss(opt, glyphList);
  let file = '';
  if (fs.existsSync(opt.cssPath)) {
    file = fs.readFileSync(opt.cssPath, 'utf8');
    let regSrc = /\/\*svgfont---start\*\/[\s\S]*\/\*svgfont---end\*\//i;
    if (!file) {
      file = cssContent;
    } else if (regSrc.test(file)) {
      file = file.replace(regSrc, cssContent);
    } else {
      file = cssContent + '\n' + file;
    }
  } else {
    file = cssContent;
  }
  fs.writeFileSync(opt.cssPath, file);
};

